// ignore: must_be_immutable

// ignore: must_be_immutable
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

class MyAlertDialog extends Dialog {
  String _title = '标配'; //标题

  String _subTitle = '副标题'; //副标题

  String _cancleBtnStr = '取消'; //取消按钮

  String _completeBtnStr = '确定'; //确定按钮

  Color _backColor = Colors.white; //背景颜色

  TextStyle _titleStyle = TextStyle(
    color: Colors.black,
    fontSize: 16,
    fontWeight: FontWeight.w600,
  ); //标题文字

  TextStyle _subtitleStyle = TextStyle(
    color: Color(0xFF999999),
    fontSize: 13,
    fontWeight: FontWeight.w400,
  ); //副标题文字

  Color _cancleBtnColor = Color(0xFFF85046); //取消按钮颜色

  Color _cancleTextColor = Colors.white; //取消按钮的文字颜色

  Color _completeTextColor = Colors.black; //完成按钮的文字颜色

  Color _completeBtnColor = Color(0xFFCCCCCC); //完成按钮颜色

  Color _completeBtnonPressedColor = Color(0xFFCCCCCC); //完成按钮按下颜色

  VoidCallback? _completeCallBack; //完成按钮回调

  VoidCallback? _cancleCallBack; //取消按钮回调

  MyAlertDialog({Key? key}) : super(key: key);

  //标题
  MyAlertDialog title(String title) {
    _title = title;
    return this;
  }

  //副标题
  MyAlertDialog subTitle(String subTitle) {
    _subTitle = subTitle;
    return this;
  }

  //取消按钮
  MyAlertDialog cancleBtnStr(String cancleBtnStr) {
    _cancleBtnStr = cancleBtnStr;
    return this;
  }

  //删除按钮
  MyAlertDialog completeBtnStr(String completeBtnStr) {
    _completeBtnStr = completeBtnStr;
    return this;
  }

  //完成按钮回调
  MyAlertDialog completeCallBack(VoidCallback callback) {
    _completeCallBack = callback;
    return this;
  }

  //取消按钮回调
  MyAlertDialog cancleCallBack(VoidCallback callback) {
    _cancleCallBack = callback;

    return this;
  }

  //背景颜色
  MyAlertDialog backColor(Color backColor) {
    _backColor = backColor;
    return this;
  }

  //取消按钮边框颜色
  MyAlertDialog cancleBtnColor(Color cancleBtnColor) {
    _cancleBtnColor = cancleBtnColor;
    return this;
  }

  //取消按钮文字颜色
  MyAlertDialog cancleTextColor(Color cancleTextColor) {
    _cancleTextColor = cancleTextColor;
    return this;
  }

  //标题
  MyAlertDialog titleStyle(TextStyle titleStyle) {
    _titleStyle = titleStyle;
    return this;
  }

  //副标题
  MyAlertDialog subtitleStyle(TextStyle subtitleStyle) {
    _subtitleStyle = subtitleStyle;
    return this;
  }

  //确认按钮颜色
  MyAlertDialog completeBtnColor(Color completeBtnColor) {
    _completeBtnColor = completeBtnColor;
    return this;
  }

  //确认按钮按下颜色
  MyAlertDialog completeBtnonPressedColor(Color completeBtnonPressedColor) {
    _completeBtnonPressedColor = completeBtnonPressedColor;
    return this;
  }

  //显示
  show() {
    Get.dialog(this);
  }

  @override
  Widget build(BuildContext context) {
    return containWidget(
      Container(
        height: 178,
        width: 256,
        color: _backColor,
        child: Stack(
          children: [
            Positioned(
              top: 20,
              left: 0,
              right: 0,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Text(_title, textAlign: TextAlign.left, style: _titleStyle),
                  SizedBox(height: 15),
                  ConstrainedBox(
                    constraints: BoxConstraints(maxWidth: 250),
                    child: Text(
                      _subTitle,
                      textAlign: TextAlign.center,
                      maxLines: 3,
                      overflow: TextOverflow.ellipsis,
                      style: _subtitleStyle,
                    ),
                  ),
                  SizedBox(height: 20,),

                   SizedBox(height: 20,)
                ],
              ),
            ),
            Positioned(
              bottom: 20,
              left: 0,
              right: 0,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  ElevatedButton(
                    onPressed: _completeCallBack!,
                    style: ElevatedButton.styleFrom(
                      backgroundColor: _completeBtnColor, // 深色背景
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                    ),
                    child: Text(
                      _completeBtnStr,
                      style: TextStyle(
                        fontSize: 15,
                        color: _completeTextColor,
                        fontWeight: FontWeight.w400,
                      ),
                    ).paddingSymmetric(horizontal: 10),
                  ),
                  SizedBox(width: 10),
                  ElevatedButton(
                    onPressed: _cancleCallBack!,
                    style: ElevatedButton.styleFrom(
                      backgroundColor: _cancleBtnColor, // 深色背景

                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(4.0),
                      ),
                    ),
                    child: Text(
                      _cancleBtnStr,
                      style: TextStyle(
                        fontSize: 15,
                        color: _cancleTextColor,
                        fontWeight: FontWeight.w400,
                      ),
                    ).paddingSymmetric(horizontal: 10),
                  ),
                  // MyOutlinedButton(
                  //   _cancleBtnStr,
                  //   textColor: _cancleTextColor,
                  //   borderColor: _cancleBorderColor,
                  //   width: 360.cw,
                  //   height: 136.ch,
                  //   radius: 68.ch,
                  //   fontSize: 64.csp,
                  //   onPressed: _cancleCallBack!,
                  //   borderWidth: 2.cw,
                  //   onPressedBorderColor: const Color.fromRGBO(8, 105, 255, 0.5),
                  // ),
                  // SizedBox(
                  //   width: 72.cw,
                  // ),
                  // MyTextButton(
                  //   _completeBtnStr,
                  //   textColor: Colors.white,
                  //   width: 360.cw,
                  //   height: 136.ch,
                  //   radius: 68.ch,
                  //   backgroudColor: _completeBtnColor,
                  //   fontSize: 64.csp,
                  //   onPressed: _completeCallBack!,
                  //   onPressedBackgroudColor: _completeBtnonPressedColor,
                  // ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  ///外围的容器
  Material containWidget(Widget childWidget) {
    return Material(
      color: Colors.transparent,
      child: Center(
        child: ClipRRect(
          borderRadius: BorderRadius.all(Radius.circular(10)),
          child: childWidget,
        ),
      ),
    );
  }
}
